// components/taskDetails/taskDetails.js

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    id: {
      type: Number
    }
  },
  lifetimes: {
    attached() {
      console.log('参数是', this.properties.id);
      this.getAppInfo()
    }

  },

  /**
   * 组件的初始数据
   */
  data: {
    isShow: false,
    actions: [
      {
        name: '010-9987 0098',
        openType: 'share',
      },
    ],
    riShow:false,
    value: '',
    top: 0,
    main:'',
    activeNames: [],
    iconShow: false,
    fileList: [
      {
        url: 'https://img.yzcdn.cn/vant/leaf.jpg',
        name: '图片1',
      },
    ],
    picList: [
      {
        url: 'https://img.yzcdn.cn/vant/leaf.jpg',
        name: '图片1',
      },
    ],
    nicList: [
      {
        url: 'https://img.yzcdn.cn/vant/leaf.jpg',
        name: '图片1',
      },
    ],
    bicList: [
      {
        url: 'https://img.yzcdn.cn/vant/leaf.jpg',
        name: '图片1',
      },
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // console.log(event);
      const n = event.detail
      if ( n !== '' ) {
        this.setData({
          main:'取消任务'
        });
      }else{
        this.setData({
          main:''
        });
      }
      this.setData({
        activeNames: event.detail,
      });
    }, 
    hIcon() {
      this.setData({ iconShow: !this.data.iconShow })
    },
    getAppInfo() {
      const res = wx.getSystemInfoSync()
      this.setData({ top: res.statusBarHeight })
    },
    onClickLeft() {
      wx.reLaunch({
        url: '/pages/index/index',
      })
      // wx.showToast({ title: '点击返回', icon: 'none' });
    },
    addPhone() {
      this.setData({ isShow: true })
    },
    onClose() {
      this.setData({ isShow: false });
    },
    onSelct() {
      this.setData({ isShow: false });
    },
    add(e) {
      console.log(e);
    },
    afterRead(event) {
      console.log(event);
      const n = event.mark.id
      const url = event.detail.file.url
      if (n) {
        this.updateImg(url, n)
      } else {
        this.updateImg(url, n)
      }
    },
    // 具体上传的操作
    updateImg(url, m) {
      wx.uploadFile({
        url: wx.$http.baseURL + '/driver/files/imageUpload',
        filePath: url,
        name: 'file',
        header: {
          Authorization: wx.getStorageSync('token')
        },
        success: (res) => {
          console.log(res)
          const n = JSON.parse(res.data)
          console.log(n)
          if (m) {
            this.data.fileList.push({ url: n.data })
            this.setData({ fileList: this.data.fileList })
          } else {
            this.data.picList.push({ url: n.data })
            this.setData({ picList: this.data.picList })
          }
        }
      })
    },
    delFile(e) {
      console.log(e)
      const n = e.mark.id
      const idx = e.detail.index
      if (n) {
        this.data.fileList.splice(idx, 1)
        this.setData({ fileList: this.data.fileList })
      } else {
        this.data.picList.splice(idx, 1)
        this.setData({ picList: this.data.picList })
      }
    },
    afterLead(event) {
      console.log(event);
      const n = event.mark.id
      const url = event.detail.file.url
      if (n) {
        this.upDate(url, n)
      } else {
        this.upDate(url, n)
      }
    },
    // 具体上传的操作
    upDate(url, m) {
      wx.uploadFile({
        url: wx.$http.baseURL + '/driver/files/imageUpload',
        filePath: url,
        name: 'file',
        header: {
          Authorization: wx.getStorageSync('token')
        },
        success: (res) => {
          console.log(res)
          const n = JSON.parse(res.data)
          console.log(n)
          if (m) {
            this.data.nicList.push({ url: n.data })
            this.setData({ nicList: this.data.nicList })
          } else {
            this.data.bicList.push({ url: n.data })
            this.setData({ bicList: this.data.bicList })
          }
        }
      })
    },
    onDel(e) {
      console.log(e)
      const n = e.mark.id
      const idx = e.detail.index
      if (n) {
        this.data.nicList.splice(idx, 1)
        this.setData({ nicList: this.data.nicList })
      } else {
        this.data.bicList.splice(idx, 1)
        this.setData({ bicList: this.data.bicList })
      }
    },
  }
})
